<section class="users panel rounded">
	<h1><?php echo lang('title_users'); ?></h1>
	
	<div class="table">
		<div class="thead">
			<div class="th email"><?php echo lang('heading_email'); ?></div>
			<div class="th group"><?php echo lang('heading_group'); ?></div>
			<div class="th active"><?php echo lang('heading_active'); ?></div>
			<div class="th actions"><?php echo lang('heading_actions'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<?php foreach ($users as $user) { ?>
			<form id="row<?php echo $user->id; ?>" action="api/user/update/<?php echo $user->id; ?>" method="post" class="row">
					<div class="td email"><input name="email" type="text" value="<?php echo $user->email; ?>" /></div>
					<div class="td group">
						<select name="access">
						<?php
							foreach (array('viewer','editor','admin') as $access) { ?>
							<option value="<?php echo $access; ?>"<?php if ($user->access==$access) echo ' selected'; ?>><?php echo $access; ?></option>
						<?php } ?>
						</select>
					</div>
					<div class="td active">
						<input type="checkbox" name="active"<?php if ($user->active) echo ' checked';?>/>
					</div>
					<div class="td actions">
						<?php if ($this->user->is_admin()) { ?>
						<a href="api/user/delete/<?php echo $user->id; ?>"><?php echo lang('action_delete'); ?></a>
						<a href="javascript:void(0);" onClick="$('#row<?php echo $user->id; ?>').submit();"><?php echo lang('action_update'); ?></a>
						<?php }
						
						if ($this->user->is_admin() || $this->user->get_current()->id == $user->id) { ?>
						<a href=""><?php echo lang('action_change_password'); ?></a>
						<?php } ?>
					</div>
					<div class="clear"></div>
			</form>
			<?php } 

			if ($this->user->is_admin()) { ?>
			<form class="new" action="api/user/insert/" method="post">
					<div class="td email">
						<input name="email" type="text"/><input id="password" type="hidden" name="password"/>
					</div>
					<div class="td group">
						<select name="access">
							<option value="" disabled></option>
						<?php
							foreach (array('viewer','editor','admin') as $access) { ?>
							<option value="<?php echo $access; ?>"><?php echo $access; ?></option>
						<?php } ?>
						</select>
										</div>
					<div class="td active">
						<input type="checkbox" name="active" checked/>
					</div>
					<div class="td actions">
						<a href="javascript:void(0);" onClick="newUser();"><?php echo lang('action_insert'); ?></a>
					</div>
					<div class="clear"></div>
			</form>
			<?php } ?>
		</div>
	
	</div>
</section>